<?php
namespace App\Http\Controllers\ApiAdmin;

use App\Service\Admin\ConfigService;
use Illuminate\Http\Request;

class ConfigController extends BaseController
{
    //配置

    public function __construct(ConfigService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getIndex(Request $request)
    {
        $id = $request->post('id', 0);
        $res = $this->db->getList($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $val = $request->post('val', '');
        $res = $this->db->modify($id, $val);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}